import React from 'react';
import { Button } from 'antd';
import { generatePrepareAlertMessage } from '../utils/interview';

const def = '-';
const mapping = {
    W: {
        label: '周评',
        target: 'assessWeekly'
    },
    M: {
        label: '月评',
        target: 'assessMonthly'
    },
    Q: {
        label: '季评',
        target: 'assessQuarterly'
    }
};

export default function usePrepareAlert(businessType = 'W', data, step = 'prepare') {
    const { employeeName = def } = data ?? {};
    const { label } = mapping[businessType];
    const stepSuffixMapping = {
        prepare: `邀请你参加${label}面谈，请进行面谈准备！`,
        record: '请记录面谈内容！'
    };

    const targetList = data?.[mapping[businessType].target] ?? [];
    const lastResult = targetList[targetList.length - 1];
    const message = generatePrepareAlertMessage(employeeName, label, lastResult, stepSuffixMapping[step]);
    const detailId = lastResult?.detailId;
    const btnText = `查看${label}详情`;

    const renderButton = React.useCallback(
        jump => (
            <Button type="link" onClick={() => jump(detailId)}>
                {btnText}
            </Button>
        ),
        [btnText, detailId]
    );
    return { message, renderButton };
}
